package com.js.springbootmongodb.controller;

import com.js.springbootmongodb.entity.Article;
import com.js.springbootmongodb.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

@Controller
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/selectAllArticle")
    @ResponseBody
    public List<Article> selectAllArticle(){
        List<Article> list = articleService.selectAllArticle();
        return list;
    }

    @GetMapping("/selectById")
    public String selectById(String articleid, Model model){
        System.out.println("取值："+articleid);
        Optional<Article> article = articleService.selectById(articleid);
        model.addAttribute("article",article);
        model.addAttribute("articleid",articleid);
        return "comment-list";
    }



}
